<?php

class Application_Model_Dao_Examstype extends Zend_Db_Table_Abstract
{

	protected $_name = 'exams_type';
	protected $_primary = 'id';

	public function init(){
			
	}
	public function getAll(){
		$result = $this->fetchAll();
		if( !$result )
		throw new Exception("Wystąpił błąd przy pobieraniu danych z bazy. Proszę spróbować jeszcze raz. Jeśli problem będzie się powtarzać, prosimy skontaktować się z administratorem.");
		return $result;
	}

	public function getAllExamsType(){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$select = $dbAdapter->select()->from('exams_type');
		$result = $dbAdapter->fetchAll($select);
		return $result;
	}
	public function getRowExamsType($id){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$select = $dbAdapter->select()->from('exams_type')->where('exams_type.id = \''.$id.'\'');
		$result = $dbAdapter->fetchAll($select);
		return $result;
	}


	public function getExamsTypeByID($id){
		$id = (int)$id;
		$row = $this->fetchRow('id = '.$id);
		if (!$row)
		throw new Exception("Rodzaj zajęć o ID $id nie istnieje.");
		return $row->toArray();
	}
	public function getExamsTypeByDesignation($designation){
		$row = $this->fetchRow('designation = '.$designation);
		if (!$row)
		throw new Exception("Rodzaj zajęć o nazwie $designation nie istnieje.");
		return $row->toArray();
	}
	public function saveExamsType($examsType) {
		$data = array(
			'designation' => $examsType->getDesignation(),
			'short' => $examsType->getShort(),
		);
		$result = $this->insert($data);
		return $result;
	}
	public function updateExamsType($examsType) {
		$data = array(
			'designation' => $examsType->getDesignation(),
			'short' => $examsType->getShort(),
		);
		$result = $this->update($data, 'id = '. (int)$examsType->getId());
		return $result;
	}
	public function deleteExamsType($examsType) {
		$result = $this->delete('id =' . (int)$examsType->getId());
		return $result;
	}
	public function getToSelect(){
		$array = $this->getAll()->toArray();
		//$examsType[''] = "wybierz";
		foreach ($array as $option) {
			$examsTypes[ $option['id'] ] = $option['designation' ] ;
		}
		return $examsTypes;
	}
	public function getToSelectClasses(){
		$array = $this->getAll()->toArray();
		$examsTypes[''] = "wybierz";
		foreach ($array as $option) {
			$examsTypes[ $option['id'] ] = $option['short'].' '.$option['designation'] ;
		}
		return $examsTypes;
	}
}
	